#include"processbar.h"

#define FileSize 1024*1024*2024  //文件的总大小1GB

void download(cal call) //模拟实际下载场景，实现进度刷新
{  //回调函数
   int filesize = FileSize; //文件总大小
   int total = FileSize;  
   while(total) 
   { 
       int one = rand()%(5*1024*1024); //单次下载量
       usleep(10000);  //表示下载的动作
       total -= one;  //还需要下载的量
       if(total < 0)
             total = 0; 
       int download = filesize - total; //已经下载的量
       double rate = download * 100.0/filesize;  //下载的进度
       call(rate);  //通过下载量，实现下载进度的刷新
   }
   printf("\n");
}

int main()
{
    srand(time(NULL)^1023); //rand->srand->time 
    download(process_flush); 
   // process();  version1
    return 0;
}
